/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/**
 * @Title: LinkTools.java
 * @Package phoenics.apeak.crawl.util
 * @Description
 * @author phoenics@126com
 * @date 2016-1-30 16:01:32
 * @version V1.0
 */
package phoenics.apeak.crawl.util;

import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;

// TODO: Auto-generated Javadoc
/**
 * The Class LinkTools.
 *
 * @Description The Class LinkTools.
 */
public class LinkTools {
	
	/**
 * Link test.
 *
 * @param url
 *            the url
 * @param errorMap
 *            the error map
 * @return the int
 * @Description Link test.
 */
	public static int LinkTest(String url,Map<String,Integer> errorMap){
		Integer x=errorMap.get(url);
		if(x==null){
			x=new Integer(0);
		}
		int xx=x.intValue();
		errorMap.put(url,  ++xx);
		return xx;
	}
	/**
	 * Xpath.
	 *
	 * @param node
	 *            the node
	 * @param path
	 *            the path
	 * @return the json node
	 * @Description Xpath.
	 */
		public static JsonNode xpath(JsonNode node, String path) {
			if (path == null || path.trim().equals("")) {
				return node;
			}
			String[] paths = path.split("\\.");
			JsonNode node_t = node;
			for (String p : paths) {
				p = p.trim();
				if (p.equals("")) {
					continue;
				}
				JsonNode pp = node_t.path(p);
				if (pp == null) {
					break;
				}
				node_t = pp;
			}
			return node_t;
		}
}
